import Vue from "vue";
import Transaction from "./index.vue";
  /**
   * 广告落地页方法 购课加微
   */
export default class AdBuy {
  constructor(goodsInfo = {}, jumpData = {}, extendInfo = {}) {
    this.goodsInfo = goodsInfo;
    this.jumpData = jumpData;
    this.extendInfo = extendInfo;
  }

  /**
   * 获取支付方式
   * @returns 返回一个对象
   * { token, payWay }：payWay: 支付方式 token: 批价接口返回的token信息
   */
  getPayWay({ option }) {
    let promiseResolve
    const resultPromise = new Promise((resolve) => {
      promiseResolve = resolve;
    })
    console.log('this.jumpData',this.jumpData);
    const TransactionConstructor = Vue.extend(Transaction);
    const instance = new TransactionConstructor({
      propsData: {
        goodsInfo: this.goodsInfo,
        jumpData: this.jumpData,
        extendInfo: this.extendInfo,
        promiseResolve,
        option
      },
    });
    instance.$mount();
    instance.initData();
    document.body.appendChild(instance.$el);

    return resultPromise
  }

  /**
   * 下单
   * @param {*} data payWay: 支付方式 token: 批价接口返回的token信息
   */
  perform(data = {}) {
    const TransactionConstructor = Vue.extend(Transaction);
    const instance = new TransactionConstructor({
      propsData: {
        goodsInfo: this.goodsInfo,
        jumpData: this.jumpData,
        extendInfo: this.extendInfo,
      },
    });
    instance.$mount();
    instance.buy(data);
    document.body.appendChild(instance.$el);
  }
}
